import Vue from 'vue'
import VueRouter from 'vue-router'
// 动态导入替换静态，实现路由懒加载，加快速度
const Login = () => import(/* webpackChunkName: "group-user" */ '../components/Login.vue')
const Home = () => import(/* webpackChunkName: "group-user" */ '../components/Home.vue')
const Welcome = () => import(/* webpackChunkName: "group-user" */ '../components/Welcome.vue')
const Users = () => import(/* webpackChunkName: "group-user" */ '../components/user/Users.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
	redirect:'/login'
  },
  {
	  path:'/login',
	  component:Login
  },
  {
  	  path:'/home',
  	  component:Home,
	  redirect:'/welcome',
	  children:[
		  {path:'/welcome',component:Welcome},
		  {path:'/users',component:Users}
	  ]
  }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to,from,next) => {
	const token = window.sessionStorage.getItem('token');
	if(to.path != '/login' && !token) return next('/login');
	next();
	
})
export default router
